<?php
namespace Game\Models\Client;

use Game\Lib\OptConst;
use Game\Module\Logger;
use Game\Module\Mysql;

class DispatcherClient
{

    /**
     * 根据操作码分发操作
     * @param $req_ary
     * @return array|int
     */
	public static function dispatcherOpt($req_ary){
		
		if(isset($req_ary['operation'])) {
			switch($req_ary['operation']) {
				/*************
					room操作
				**************/
				case 'CreateRoom':		//创建房间
					$roomModel = new RoomModel();
					$result = $roomModel->createRoom($req_ary);
					break;
                case 'PrepareJoinRoom':		//进房之前的查询
                    $roomModel = new RoomModel();
                    $result = $roomModel->prepareJoinRoom($req_ary);
                    break;
                case 'JoinRoom':		//进入房间
                    $roomModel = new RoomModel();
                    $result = $roomModel->joinRoom($req_ary);
                    break;


				case 'GuestRoom':		//观战
					$roomModel = new RoomModel();
					$result = $roomModel->guestRoom($req_ary);
					break;

				case 'ReadyStart':		//用户准备操作
					$roomModel = new RoomModel();
					$result = $roomModel->readyStart($req_ary);
					break;
				case 'ReadyCancel':		//用户取消准备操作
					$roomModel = new RoomModel();
					$result = $roomModel->readyCancel($req_ary);
					break;

				case 'PullRoomInfo':		//拉取房间信息
					$roomModel = new RoomModel();
					$result = $roomModel->pullRoomInfo($req_ary);
					break;
				case 'HistoryScoreboard':		//历史积分榜
					$roomModel = new RoomModel();
					$result = $roomModel->historyScoreboard($req_ary);
					break;
				case 'LastScoreboard':		//历史战绩
					$roomModel = new RoomModel();
					$result = $roomModel->lastScoreboard($req_ary);
					break;
					
                case 'CloseRoom':		//拉取房间信息
                    $roomModel = new RoomModel();
                    $result = $roomModel->closeRoom($req_ary);
                    break;

				case 'ClickToLook':		//点击看牌
					$playModel = new PlayModel();
					$result = $playModel->clickToLook($req_ary);
					break;
				case 'ChooseChip':		//选择筹码
					$playModel = new PlayModel();
					$result = $playModel->ChooseChip($req_ary);
					break;

				case 'Discard':		//弃牌
					$playModel = new PlayModel();
					$result = $playModel->discard($req_ary);
					break;
				case 'OpenCard':		//开牌
					$playModel = new PlayModel();
					$result = $playModel->openCard($req_ary);
					break;

				case 'PkCard':		//开牌
					$playModel = new PlayModel();
					$result = $playModel->pkCard($req_ary);
					break;
				case 'BroadcastVoice':		//发送声音
					$playModel = new PlayModel();
					$result = $playModel->broadcastVoice($req_ary);
					break;

				case 'SpeakVoice':		//发送声音2
					$playModel = new PlayModel();
					$result = $playModel->speakVoice($req_ary);
					break;

				case 'LxhServer':		//观察员用于调试收取房间消息
					$playModel = new PlayModel();
					$result = $playModel->LxhServer($req_ary);
					break;
				
				default:
					$result = OptConst::MISSING_OPERATION;	//数据格式不正确，缺少操作码
					break;
			}

			//关闭数据库
			Mysql::closeAll();
            Logger::getInstance()->debug($req_ary);
			Logger::getInstance()->debug($result);
			return $result;
		} else {
			return OptConst::MISSING_OPERATION;	//缺少操作码
		}
	}

	
	/*
		断开操作
	*/
	public static function socketClosed($array){
		$roomModel = new RoomModel();
		$result = $roomModel->userDisconnected($array);
		return $result;
	}
	
}